package org.jeecg.modules.system.rule;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.handler.IFillRuleHandler;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.engine.entity.Task;
import org.jeecg.modules.engine.service.ITaskService;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TaskNumberRule implements IFillRuleHandler {
    @Override
    public Object execute(JSONObject params, JSONObject formData) {
        ITaskService taskService = (ITaskService) SpringContextUtils.getBean("taskServiceImpl");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String currDay = simpleDateFormat.format(new Date());
        int count = taskService.count(new LambdaQueryWrapper<Task>().ge(Task::getCreateTime, currDay + " 00:00:00").and(p -> p.le(Task::getCreateTime, currDay + " 23:59:59")));
        String prefix = "WK";
        String dateFormat = new SimpleDateFormat("yyyyMMdd").format(new Date());
        return prefix+dateFormat+String.format("%04d",count+1);
    }
}
